import {
  dirTree,
  currentDirList,
  mkdir,
  deleteDir,
  rename,
  copy,
  move,
  getRecycleBin,
  recovery,
  removeCompletely,
  cleanRecyclingBin
} from '@/api/dir';

const state = {
  userId: null
};

const mutations = {
  SET_USERID(state, userId) {
    state.userId = userId;
  }
};
const actions = {
  dirTree({ commit }, param) {
    return new Promise((resolve, reject) => {
      dirTree(param)
        .then(res => {
          const { data } = res;
          if (data) {
            console.log(data);
          }
          resolve(data);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  currentDirList({ commit }, param) {
    return new Promise((resolve, reject) => {
      currentDirList(param)
        .then(res => {
          const { data } = res;
          if (data) {
            console.log(data);
          }
          resolve(data);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  mkdir({ commit }, param) {
    return new Promise((resolve, reject) => {
      mkdir(param)
        .then(res => {
          const { data } = res;
          if (data) {
            console.log(data);
          }
          resolve(data);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  deleteDir({ commit }, param) {
    return new Promise((resolve, reject) => {
      deleteDir(param)
        .then(res => {
          const { data } = res;
          if (data) {
            console.log(data);
          }
          resolve(data);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  rename({ commit }, param) {
    return new Promise((resolve, reject) => {
      rename(param)
        .then(res => {
          const { data } = res;
          if (data) {
            console.log(data);
          }
          resolve(data);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  copy({ commit }, param) {
    return new Promise((resolve, reject) => {
      copy(param)
        .then(res => {
          const { data } = res;
          if (data) {
            console.log(data);
          }
          resolve(data);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  move({ commit }, param) {
    return new Promise((resolve, reject) => {
      move(param)
        .then(res => {
          const { data } = res;
          if (data) {
            console.log(data);
          }
          resolve(data);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  getRecycleBin({ commit }, param) {
    return new Promise((resolve, reject) => {
      getRecycleBin(param)
        .then(res => {
          const { data } = res;
          if (data) {
            console.log(data);
          }
          resolve(data);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  recovery({ commit }, param) {
    return new Promise((resolve, reject) => {
      recovery(param)
        .then(res => {
          const { data } = res;
          if (data) {
            console.log(data);
          }
          resolve(data);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  cleanRecyclingBin({ commit }, param) {
    return new Promise((resolve, reject) => {
      cleanRecyclingBin(param)
        .then(res => {
          const { data } = res;
          if (data) {
            console.log(data);
          }
          resolve(data);
        })
        .catch(err => {
          reject(err);
        });
    });
  },
  removeCompletely({ commit }, param) {
    return new Promise((resolve, reject) => {
      removeCompletely(param)
        .then(res => {
          const { data } = res;
          if (data) {
            console.log(data);
          }
          resolve(data);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
